package com.itheima.sh.controller;

import com.itheima.sh.pojo.User;
import com.itheima.sh.response.ResponseResult;
import com.itheima.sh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;


    @GetMapping
    public ResponseResult<User> findAll() {
        return ResponseResult.okResult(userService.findAll());
    }

    @PostMapping
    public ResponseResult<User> add( @RequestBody User user){
        if (true) {
            throw new IndexOutOfBoundsException("御姐");
        }
        return ResponseResult.okResult(userService.add(user));
    }

}
